install pySal
NB:make sure you start your work with new directory with all library
import mapclassify as mc
import geopandas as gpd
import matplotlib.pyplot as plt
import contextily as cx
ethio = gpd.read_file("C:/Users/agurm/Downloads/pysal-scipy20-master/Eth GIS/eth_watshed.shp")
ethio.columns
Index(['AREA', 'PERIMETER', 'ETWSHED01C', 'BASIN_NR', 'BASIN_NAME', 'BASIN',
'SQKM', 'BASIN_COD', 'geometry'],
dtype='object')
ethio
| AREA | PERIMETER | ETWSHED01C | BASIN_NR | BASIN_NAME | BASIN | SQKM | BASIN_COD | geometry | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1.503697e+09 | 201961.90894 | 110 | 11 | Mereb | 110 | 15208 | 2A1 | POLYGON ((431294.827 1602480.205, 430185.938 1... |
| 1 | 1.232069e+09 | 199722.49770 | 121 | 12 | Tekeze | 121 | 1954 | 3B1 | POLYGON ((393200.000 1596000.000, 393127.219 1... |
| 2 | 2.173783e+08 | 86924.09546 | 233 | 23 | Danakil | 233 | 550 | 14D1 | POLYGON ((585026.438 1604424.500, 584441.750 1... |
| 3 | 7.157738e+08 | 162011.35318 | 111 | 11 | Mereb | 111 | 1201 | 2B6 | POLYGON ((542535.082 1605247.134, 542817.563 1... |
| 4 | 1.637719e+09 | 260200.47067 | 110 | 11 | Mereb | 110 | 15208 | 2A1 | POLYGON ((503860.813 1617412.625, 503959.125 1... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 653 | 2.113343e+08 | 70832.95709 | 212 | 21 | Awash | 212 | 211 | 12C16 | POLYGON ((558000.000 1026000.000, 558478.250 1... |
| 654 | 2.088036e+08 | 64158.26747 | 212 | 21 | Awash | 212 | 208 | 12C17 | POLYGON ((554800.000 1021200.000, 555600.563 1... |
| 655 | 7.490104e+07 | 46678.58684 | 212 | 21 | Awash | 212 | 74 | 12C18 | POLYGON ((554000.000 1020400.000, 553986.563 1... |
| 656 | 8.817818e+08 | 132929.29581 | 212 | 21 | Awash | 210 | 881 | 12C13 | POLYGON ((673200.000 1025600.000, 673236.000 1... |
| 657 | 2.913601e+10 | 896494.14814 | 990 | 21 | Awash | 211 | 29136 | 9999 | POLYGON ((747713.625 1225637.875, 748922.438 1... |
658 rows × 9 columns
f, ax = plt.subplots(1, figsize=(12, 8))
ethio.plot(column='BASIN', scheme='QUANTILES', ax=ax,
edgecolor='white', legend=True, linewidth=0.3)
ax.set_axis_off()
plt.show()
As a first cut, geopandas makes it very easy to plot a map quickly. If you know the area well, this may do fine for quick exploration. If you don't know a place extremely well (or you want to make a figure easy to understand for those who don't) it's often a good idea to add a basemap for context. We can do that easily using the contextily package
ethio.fillna(ethio.mean(), inplace = True)
f, ax = plt.subplots(1, figsize=(12, 8))
ethio.plot(column='BASIN', scheme='QUANTILES', alpha=0.6, ax=ax, legend=True)
cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite)
ax.set_axis_off()
plt.show()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-6-709446de3aa7> in <module> 1 f, ax = plt.subplots(1, figsize=(12, 8)) 2 ethio.plot(column='BASIN', scheme='QUANTILES', alpha=0.6, ax=ax, legend=True) ----> 3 cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite) 4 ax.set_axis_off() 5 plt.show() AttributeError: 'NoneType' object has no attribute 'to_string'
hv = ethio['BASIN']
mc.Quantiles(hv, k=5)
Quantiles
Interval Count
------------------------
[110.00, 131.00] | 156
(131.00, 141.00] | 116
(141.00, 162.00] | 136
(162.00, 181.00] | 122
(181.00, 990.00] | 128
mc.Quantiles(hv, k=10)
Quantiles
Interval Count
------------------------
[110.00, 124.00] | 73
(124.00, 131.00] | 83
(131.00, 132.00] | 51
(132.00, 141.00] | 65
(141.00, 152.00] | 62
(152.00, 162.00] | 74
(162.00, 172.00] | 82
(172.00, 181.00] | 40
(181.00, 212.00] | 70
(212.00, 990.00] | 58
q10 = mc.Quantiles(hv, k=10)
dir(q10)
['__call__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_classify', '_fmt', '_set_bins', '_summary', '_table_string', '_update', 'adcm', 'bins', 'classes', 'counts', 'find_bin', 'fmt', 'gadf', 'get_adcm', 'get_fmt', 'get_gadf', 'get_legend_classes', 'get_tss', 'k', 'make', 'name', 'plot', 'set_fmt', 'table', 'tss', 'update', 'y', 'yb']
q10.bins
array([124., 131., 132., 141., 152., 162., 172., 181., 212., 990.])
q10.counts
array([73, 83, 51, 65, 62, 74, 82, 40, 70, 58], dtype=int64)
fj10 = mc.FisherJenks(hv, k=10)
fj10
FisherJenks
Interval Count
------------------------
[110.00, 125.00] | 75
(125.00, 135.00] | 176
(135.00, 153.00] | 86
(153.00, 164.00] | 80
(164.00, 175.00] | 100
(175.00, 192.00] | 28
(192.00, 220.00] | 60
(220.00, 252.00] | 29
(252.00, 281.00] | 15
(281.00, 990.00] | 9
fj10.adcm
1372.0
q10.adcm
8611.0
bins = [100000, 500000, 1000000, 1500000]
ud4 = mc.UserDefined(hv, bins=bins)
ud4
UserDefined
Interval Count
--------------------------------
[ 110.00, 100000.00] | 658
( 100000.00, 500000.00] | 0
( 500000.00, 1000000.00] | 0
(1000000.00, 1500000.00] | 0
f, ax = plt.subplots(1, figsize=(12, 8))
ethio.plot(column='BASIN', scheme='QUANTILES', ax=ax, alpha=0.6, legend=True)
cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite)
ax.set_axis_off()
plt.show()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-21-81b7d92baa5e> in <module> 2 ethio.plot(column='BASIN', scheme='QUANTILES', ax=ax, alpha=0.6, legend=True) 3 ----> 4 cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite) 5 ax.set_axis_off() 6 plt.show() AttributeError: 'NoneType' object has no attribute 'to_string'
f, ax = plt.subplots(1, figsize=(12, 8))
ethio.plot(column='BASIN', scheme='FisherJenks', ax=ax,
alpha=0.6, legend=True)
cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite)
ax.set_axis_off()
plt.show()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-22-4a9ba35c4cf1> in <module> 3 alpha=0.6, legend=True) 4 ----> 5 cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite) 6 7 ax.set_axis_off() AttributeError: 'NoneType' object has no attribute 'to_string'
f, ax = plt.subplots(1, figsize=(12, 8))
ethio.plot(column='BASIN', scheme='FisherJenks', ax=ax,
alpha=0.6, legend=True, cmap='Blues')
cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite)
ax.set_axis_off()
plt.show()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-23-df102f128a29> in <module> 3 alpha=0.6, legend=True, cmap='Blues') 4 ----> 5 cx.add_basemap(ax, crs=ethio.crs.to_string(), source=cx.providers.Stamen.TonerLite) 6 7 ax.set_axis_off() AttributeError: 'NoneType' object has no attribute 'to_string'
import numpy as np
import geoviews as gv
import geoviews.feature as gf
import xarray as xr
from cartopy import crs
import hvplot.pandas
import geopandas as gpd
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
cities.hvplot(global_extent=True, frame_height=450, tiles=True)
shp_link = 'C:/Users/agurm/Downloads/pysal-scipy20-master/Eth GIS/eth_watshed.shp'
gdf = gpd.read_file(shp_link)
gdf.fillna(gdf.mean(), inplace = True)
gdf.hvplot()
Beyond choropleth maps: A review of techniques to visualize quantitative areal geodata link.
Dynamic Choropleth Maps - Using Amalgamation to Increase Area Perceivability link
Exploring the Sensitivity of Choropleths under Attribute Uncertainty link.